﻿using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using CivilRegistry.ControlledModel.Repository;

[assembly: InternalsVisibleTo("Test")]

namespace CivilRegistry.ControlledModel
{
    /// <summary>
    /// The voter card object.
    /// </summary>
    public partial class VoterCard : ICard
    {
        #region Local Fields

        /// <summary>
        /// Holds the <see cref="VoterCardRepository"/> instance.
        /// </summary>
        static VoterCardRepository repository = new VoterCardRepository();

        #endregion

        #region Methods

        #region CRUD Methods

        #region Finder Methods

        /// <summary>
        /// Finds the <see cref="VoterCard"/> by Id.
        /// </summary>
        /// <param name="id">The id of the <see cref="VoterCard"/>.</param>
        /// <returns>Found <see cref="VoterCard"/> object, null if not found.</returns>
        public static VoterCard FindById(int id)
        {
            return repository.FindBy(voterCard => voterCard.VoterCardId == id);
        }

        /// <summary>
        /// Finds the <see cref="VoterCard"/> by <see cref="Person"/>.
        /// </summary>
        /// <param name="person">The <see cref="Person"/> object.</param>
        /// <returns>Found <see cref="VoterCard"/> object, null if not found.</returns>
        public static VoterCard FindByPerson(Person person)
        {
            return repository.FindBy(voterCard => voterCard.Person == person);
        }

        /// <summary>
        /// Finds all <see cref="VoterCard"/>s.
        /// </summary>
        /// <returns>Found <see cref="VoterCard"/> objects, empty if none are found.</returns>
        internal static List<VoterCard> FindAll()
        {
            return repository.FindAll();
        }

        /// <summary>
        /// Finds all <see cref="VoterCard"/>s.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns>Found <see cref="VoterCard"/> objects, empty if none are found.</returns>
        internal static List<VoterCard> FindAll(Func<VoterCard, bool> predicate)
        {
            return repository.FindAll(predicate);
        }

        /// <summary>
        /// Retrives <see cref="VoterCard"/>s by provided conditions.
        /// </summary>
        /// <param name="approved">Approved flag.</param>
        /// <param name="deactivated">Deactivated flag.</param>
        /// <returns>Found <see cref="VoterCard"/> objects, empty if none are found.</returns>
        internal static List<VoterCard> GetRecordsBy(bool approved, bool deactivated)
        {
            return repository.GetRecordsBy(approved, deactivated, predicate => true);
        }

        /// <summary>
        /// Retrives <see cref="VoterCard"/>s by provided conditions.
        /// </summary>
        /// <param name="approved">Approved flag.</param>
        /// <param name="deactivated">Deactivated flag.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>Found <see cref="VoterCard"/> objects, empty if none are found.</returns>
        internal static List<VoterCard> GetRecordsBy(bool approved, bool deactivated, Func<VoterCard, bool> predicate)
        {
            return repository.GetRecordsBy(approved, deactivated, predicate);
        }

        /// <summary>
        /// Retrives the deactive <see cref="VoterCard"/>s.
        /// </summary>
        /// <returns>The deactive <see cref="VoterCard"/>s.</returns>
        internal static List<VoterCard> GetDeactiveRecords()
        {
            return repository.GetDeactiveRecords(predicate => true);
        }

        /// <summary>
        /// Retrives the deactive <see cref="VoterCard"/>s by provided condition.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns>The deactive <see cref="VoterCard"/>s.</returns>
        internal static List<VoterCard> GetDeactiveRecords(Func<VoterCard, bool> predicate)
        {
            return repository.GetDeactiveRecords(predicate);
        }

        /// <summary>
        /// Retrives the approved <see cref="VoterCard"/>s.
        /// </summary>
        /// <returns>The approved <see cref="VoterCard"/>s.</returns>
        internal static List<VoterCard> GetApprovedRecords()
        {
            return repository.GetApprovedRecords(predicate => true);
        }

        /// <summary>
        /// Retrives the approved <see cref="VoterCard"/>s by provided condition.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns>The approved <see cref="VoterCard"/>s.</returns>
        internal static List<VoterCard> GetApprovedRecords(Func<VoterCard, bool> predicate)
        {
            return repository.GetApprovedRecords(predicate);
        }

        /// <summary>
        /// Retrives the non-approved <see cref="VoterCard"/>s.
        /// </summary>
        /// <returns>The non-approved <see cref="VoterCard"/>s.</returns>
        internal static List<VoterCard> GetNonApprovedRecords()
        {
            return repository.GetNonApprovedRecords(predicate => true);
        }

        /// <summary>
        /// Retrives the non-approved <see cref="VoterCard"/>s by provided condition.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns>The non-approved <see cref="VoterCard"/>s.</returns>
        internal static List<VoterCard> GetNonApprovedRecords(Func<VoterCard, bool> predicate)
        {
            return repository.GetNonApprovedRecords(predicate);
        }

        #endregion

        #region CUD Methods

        /// <summary>
        /// To save the changes made to this object.
        /// </summary>
        /// <returns>Saved <see cref="VoterCard"/> object.</returns>
        internal VoterCard SaveChanges()
        {
            return repository.Update(this);
        }

        /// <summary>
        /// To insert the <see cref="VoterCard"/>.
        /// </summary>
        /// <param name="voterCard">The <see cref="VoterCard"/> to insert.</param>
        /// <returns>The inserted <see cref="VoterCard"/> object.</returns>
        internal static VoterCard Insert(VoterCard voterCard)
        {
            return repository.Insert(voterCard);
        }

        /// <summary>
        /// To update the <see cref="VoterCard"/>.
        /// </summary>
        /// <param name="voterCard">The <see cref="VoterCard"/> to update.</param>
        /// <returns>The updated <see cref="VoterCard"/> object.</returns>
        internal static VoterCard Update(VoterCard voterCard)
        {
            return repository.Update(voterCard);
        }

        /// <summary>
        /// To delete the <see cref="VoterCard"/>.
        /// </summary>
        /// <param name="voterCard">The <see cref="VoterCard"/> to delete.</param>
        internal static void Delete(VoterCard voterCard)
        {
            repository.Delete(voterCard);
        }

        #endregion

        #endregion

        #endregion
    }
}